﻿using System;
using System.ComponentModel;
using System.Web.UI;
using System.Xml;
using Library.WebControls.Ds;
using Library.WebControls.SimpleCombobox;

namespace Library.WebControls.SimpleGridView {
	/// <summary>
	/// Combox grid column
	/// </summary>
	//[ParseChildren(true, "EditCombobox")]
	//[PersistChildren(true)]
	public class SpGvComboxColumn : SpGvBaseColumn {
		/// <summary>
		/// create combo grid column instance
		/// </summary>
		public SpGvComboxColumn() {
			EditCombobox = new EditTextEdit(this);
			EditValueMode = EditValueMode.Attribute;

		}
		/// <summary>
		/// Get Column type
		/// </summary>
		public override GridColumnType ColumnType {
			get { return GridColumnType.ComboEdit; }
		}
		private class EditTextEdit : SpCombobox {
			private readonly SpGvBaseColumn _column;
			
			public EditTextEdit(SpGvBaseColumn column) {
				_column = column;
			}

			public override bool Visible {
				get { return _column.Visible; }
				set {

				}
			}
			[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
			[Browsable(false)]
			public override string ClientName {
				get {
					return base.ClientName;
				}
				set {
					base.ClientName = value;
				}
			}
			[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
			[Browsable(false)]
			
			public override string ID {
				get {
					return base.ID;
				}
				set {
					base.ID = value;
				}
			}

			
			
		}


		///<summary>
		/// Combox edit control
		///</summary>
		[PersistenceMode(PersistenceMode.InnerProperty)]
		[MergableProperty(false)]
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
		public SpCombobox EditCombobox { get; private set; }

		internal override BaseControl CreateClientEditControl() {
			return EditCombobox;
		}

		protected override string GetTextFromObject(object value) {

			var result = EditCombobox.GetTextObject(value);
			if (result != null)
				return base.GetTextFromObject(result);
			return base.GetTextFromObject(value);
		}

	

		protected override string GetValueFromObject(object value) {
			if (value == null) return String.Empty;
			return value.ToString();
		}
	}
}
